package homework4

import akka.actor.{Actor, ActorRef, ActorSystem, Props}

class BActor extends Actor{

  val bActorRef = ActorSystem("myFactory").actorOf(Props[BActor], "bActor")

  override def receive: Receive = {
    case ("我打", actorRef: ActorRef) => {
      val str = "挺猛，看我降龙十八掌...第1掌"
      sendMessage(str, actorRef)
    }
    case ("厉害！佛山无影脚 第1脚", actorRef: ActorRef) => {
      val str = "挺猛，看我降龙十八掌...第2掌"
      sendMessage(str, actorRef)
    }
    case "到此为止吧！" => {
       //关闭自己
      context.stop(self)
       //关闭ActorSystem
      context.system.terminate()
    }
  }

  def sendMessage(str: String, actorRef: ActorRef): Unit = {
    println(s"BActor(乔峰): $str")
    actorRef ! (str, bActorRef)
  }
}
